(function ($) {
    var installButton,
        messages;

    function init() {
        installButton   = $('#bridge-install');
        messages        = $('#messages');
    }

    function onDomReady() {
        init();

        installButton.click(function () {
            $(this).val('Installing Theme . . . . .');

            $.ajax({
                type : 'POST',
                url  : Bridge.wp_ajax_url,
                data : {
                    action: 'BridgeInstall',
                    copy_dest   : Bridge.copy_dest,
                    copy_src    : Bridge.copy_src
                },
                success: function (data) {
                    var msg = '';

                    if (data == 'success') {
                        msg = '<h1 class="success">Success</h1>'
                         +   '<p>You have successfully installed "Natural Theme". Please go to <a href="themes.php" class="path">Appearance > Themes</a> to confirm.</p>';
                    } else if (data == 'fail') {
                        msg = '<h1 class="error">Error</h1>'
                         + '<p>An error occured. Please refresh the page and try again.</p>';
                    }

                    messages.html(msg);
                }
            })
        });
    }

    $(document).ready(onDomReady);
}(jQuery));